﻿
using System;
namespace AgFractal.Fractals
{
    public class BarnsleyMandel: AbstractFractal
    {
        public BarnsleyMandel()
        {
            ID = new Guid("0155969A-9116-4b85-9C35-124AC9508358");
            Name = Description = "Barnsley mandel";
            R1 = -3; I1 = 2; R2 = 3; I2 = -2;
        }

        protected override short Calculate(double r, double i, short MaxIteration)
        {
            short j;
            Complex z = new Complex(r, i);
            Complex c = new Complex(r, i);
            for (j = 0; j < MaxIteration; j++)
            {
                if (z.r >= 0)
                    z.r = z.r - 1;
                else
                    z.r = z.r + 1;

                z = z * c;
                if (z.Abs2() > 4) break;
            }
            return j;            
        }
    }
}
